import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/components/Login";
import Home from "@/components/Home";
import Welcome from "@/components/Welcome";
import Register from "@/components/vehicle/Register";
import Registration from "@/components/driver/Registration";
import centre1 from "@/components/Examples/Welcome/centre1";
import centre2 from "@/components/Examples/Welcome/centre2";
import centre3 from "@/components/Examples/Welcome/centre3";
import Conduct from "@/components/behavior/Conduct";
import Add from "@/components/driver/Add";
import Track from "@/components/vehicle/Track";

Vue.use(VueRouter)


const router = new VueRouter({
    mode: 'history',
    routes: [
        {path: '/', redirect: '/login'},
        {path: '/login', component: Login},
        {
            path: '/home',
            component: Home,
            redirect: '/welcome',
            children: [
                {
                    path: '/welcome', component: Welcome, redirect: '/centre1',
                    children: [
                        {path: '/centre1', component: centre1},
                        {path: '/centre2', component: centre2},
                        {path: '/centre3', component: centre3},
                    ]
                },
                {path: '/register', component: Register},
                {path: '/registration', component: Registration},
                {path: '/conduct', component: Conduct},
                {path: '/driver/add', component: Add},
                {path: '/track', component: Track},
            ]
        }
    ]
})

// // 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   // to 将要访问的路径
//   // from 代表从哪个路径跳转而来
//   // next 是一个函数，表示放行
//   //     next()  放行    next('/login')  强制跳转
//
//   if (to.path === '/login') return next()
//   // 获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) return next('/login')
//   next()
// })


export default router
